<?php
class Eventos_model extends CI_Model{
	
	private $table = 'solicitacao';
	
	function __construct(){
		parent::__construct();
	}
	
	public function get($year = NULL , $month = NULL){
		$year  = (is_null($year))?	date('Y') : $year;
		$month = (is_null($month))? date('m') : $month;
		$event = $this->db->where('data BETWEEN '.$year.'-'.$month.'-01 and '.$year.'-'.$month.'-31')->from($this->table)->get()->result();
		$days = array();
		
		foreach($event as $ev){
			$date = explode('/',$ev->DATA_REALIZACAO);
			$days[ $date['0'] ] = $ev->id; 
		}
		
		return $days;
	}
	
	public function get_timeline(){
		$year  = date('Y');
		$month = date('m');
		$day   = date('d');
		return $this->db->where('data BETWEEN '.$year.'-'.$month.'-'.($day-7).' and '.$year.'-'.$month.'-'.($day+7))->from($this->table)->get()->result();
	}
	
	public function buscar($value){
		$exploded = explode(' ',$value);
		$recordset = $this->db->from($this->table);
		foreach($exploded as $arg) $recordset->where_or('%tag%',$arg);
		return $recordset->get()->result();
	}
	
	public function novo($postarray){
		if($this->db->insert($this->table,$postarray)) return true;
		else return false;
	}
}